package org.xwb.classloader;

class A{
    static {
        try {
            Thread.sleep(1000);
            Class.forName("org.xwb.classloader.B");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

class B{
    static {
        try {
            Thread.sleep(1000);
            Class.forName("org.xwb.classloader.A");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
public class ClassLoaderDeadLock extends Thread{

        private String className;
        public ClassLoaderDeadLock(String className) {
            this.className = className;
            this.setName("Thread"+className);
        }
        @Override
        public void run() {
            try {
                Class.forName("org.xwb.classloader."+className);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }


    public static void main(String[] args) {
        new ClassLoaderDeadLock("A").start();
        new ClassLoaderDeadLock("B").start();
        System.out.println("Hello, World!");
    }
}